package com.exonline.listener;

import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.annotation.WebListener;

/**
 * @desc: 监听ServletContext域的创建与销毁的监听器ServletContextListener
 * @duthor: jjr
 */
@WebListener
public class ServletContextListener implements javax.servlet.ServletContextListener {
    @Override
    //监听context域对象的创建
    public void contextInitialized(ServletContextEvent sce) {
        //就是被监听的对象---ServletContext
        ServletContext servletContext = sce.getServletContext();
        //getSource就是被监听的对象的通用的方法
        ServletContext source = (ServletContext) sce.getSource();
        System.out.println("Servletcontext已创建");
    }
    //监听Servletcontext域对象的销毁
    @Override
    public void contextDestroyed(ServletContextEvent sce) {
        System.out.println("Servletcontext已销毁");
    }
}

